package com.qianniu.napi.admin.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.base.Strings;
import com.qianniu.napi.admin.entity.Reserve;
import com.qianniu.napi.admin.mapper.ReserveMapper;
import com.qianniu.napi.admin.service.IReserveService;
import com.qianniu.napi.common.util.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenxuebin
 * @since 2017-08-09
 */
@Service
public class ReserveServiceImpl extends ServiceImpl<ReserveMapper, Reserve> implements IReserveService {

    @Autowired
    private ReserveMapper reserveMapper;

    public void saveReserve(Reserve reserve){

        reserveMapper.insertReserve(reserve);
    }

    public List<Reserve> getReserveList(String date, String roomNo){

        Map map = new HashMap<String,Object>();
        map.put("date",date);
        if(Strings.isNullOrEmpty(date))date = TimeUtils.getToday();
        if(date.length()>7){
            map.put("month",date.substring(0,7));
        }
        map.put("roomNo",roomNo);
        map.put("isCancel",0);
        return reserveMapper.selectReserveList(map);
    }

    public List<Reserve> getMyReserveList(String date, String uid){

        Map map = new HashMap<String,Object>();
        map.put("date",date);

        map.put("uid",uid);
        map.put("isCancel",0);
        return reserveMapper.selectMyReserveList(map);
    }

    public Reserve findReserveById(String id){

        return reserveMapper.selectReserveById(id);
    }

    public void cancelReserve(String id){

        Map<String,Object> map = new HashMap<String,Object>();
        map.put("id",id);
        map.put("isCancel",1);
        reserveMapper.updateReserve(map);
    }

    public void modifyReserve(Map map){

        reserveMapper.updateReserve(map);
    }

}
